home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Win 50 Game+ Vol. 7 (Japan)
/
Win 50 Game+ Vol. 7 (Japan).7z
/
Win 50 Game+ Vol. 7 (Japan).bin
/
lha_file
/
dpgolf11.lzh
/
DPG11SRC.LZH
/
GLMAIN.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1996-08-21
|
13KB
|
481 lines
unit Glmain;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, about, Menus, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
Exit1: TMenuItem;
N1: TMenuItem;
Restart1: TMenuItem;
Help1: TMenuItem;
About1: TMenuItem;
Index1: TMenuItem;
Panel1: TPanel;
Shape1: TShape;
Image2: TImage;
Image3: TImage;
hata: TImage;
Timer1: TTimer;
New1: TMenuItem;
Shape2: TShape;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Bar1: TScrollBar;
Bar2: TScrollBar;
Label5: TLabel;
Label6: TLabel;
Button1: TButton;
showxy: TLabel;
Save1: TMenuItem;
Load1: TMenuItem;
Game1: TMenuItem;
Loadbox: TOpenDialog;
Savebox: TSaveDialog;
N2: TMenuItem;
Radio1: TRadioGroup;
Check1: TCheckBox;
procedure About1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure Shape1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Shape1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; MX, MY: Integer);
procedure Timer1Timer(Sender: TObject);
procedure New1Click(Sender: TObject);
procedure Restart1Click(Sender: TObject);
procedure Bar1Change(Sender: TObject);
procedure Bar2Change(Sender: TObject);
procedure ResetbtnClick(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure Shape1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Shape2MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Help1Click(Sender: TObject);
procedure Save1Click(Sender: TObject);
procedure Load1Click(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; MX, MY: Integer);
procedure Check1Click(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private ÉΘî╛ }
procedure showhole;
procedure pmstr(n : integer);
public
{ Public ÉΘî╛ }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
type str12 = string[12];
var map : array[1..18,0..17,0..17] of byte;
dx, dy : array[1..18,1..16,1..16] of shortint;
hx, hy, bx, by : array[1..18] of byte;
hole, shot, score : integer;
data : file of byte;
rect1, rect2 : Trect;
nopress, cupin, nomove : boolean;
x, y, bdx, bdy, fr, ac : real;
path, fname : string;
procedure readcourse;
var i, j, k : byte;
begin
screen.cursor := crHourglass;
for i := 1 to 18 do for j := 0 to 17 do for k := 0 to 17 do map[i,k,j] := $88;
assignfile(data,fname);
reset(data);
if filesize(data) < 4644 then begin
randseed := filesize(data);
for i := 1 to 18 do begin
for j := 1 to 16 do for k := 1 to 16 do begin
map[i,k,j] := random(256);
dx[i,k,j] := map[i,k,j] mod 16 - 8;
dy[i,k,j] := map[i,k,j] div 16 - 8;
end;
hx[i] := random(16) + 1;
hy[i] := random(16) + 1;
repeat
bx[i] := random(16) + 1;
by[i] := random(16) + 1;
until (hx[i] <> bx[i]) or (hy[i] <> by[i]);
end;
end else for i := 1 to 18 do begin
for j := 1 to 16 do for k := 1 to 16 do begin
read(data,map[i,k,j]);
dx[i,k,j] := map[i,k,j] mod 16 - 8;
dy[i,k,j] := map[i,k,j] div 16 - 8;
end;
read(data,j,k);
hx[i] := j mod 16 + 1;
hy[i] := j div 16 + 1;
k := 255 - k;
bx[i] := k mod 16 + 1;
by[i] := k div 16 + 1;
end;
closefile(data);
for i := 1 to 18 do for j := 0 to 17 do for k := 0 to 17 do
if map[i,k,j] = $88 then map[i,k,j] := 0 else map[i,k,j] := 1;
screen.cursor := crDefault;
end;
procedure Tform1.pmstr(n : integer);
begin
if n < 0 then label3.caption :=
'Score ' + inttostr(score) + ' (' + inttostr(n) + ')'
else label3.caption :=
'Score ' + inttostr(score) + ' (+' + inttostr(n) + ')';
end;
procedure Tform1.showhole;
var i, j : byte;
begin
x := bx[hole] + 0.5;
y := by[hole] + 0.5;
cupin := false;
formpaint(exit1);
hata.left := (hx[hole] - 1) * 26 + 8;
hata.top := (hy[hole] - 1) * 26 - 15;
hata.refresh;
shot := 1;
label1.caption := 'Hole ' + inttostr(hole) + ' (par 2)';
label2.caption := 'Shot 1';
pmstr(score - (hole - 1) * 2);
label4.show;
end;
procedure TForm1.Restart1Click(Sender: TObject);
begin
score := 0;
hole := 1;
showhole;
end;
procedure TForm1.New1Click(Sender: TObject);
begin
with aboutbox do begin
clientheight := 165;
okbutton.hide;
makebtn.show;
cancelbtn.show;
combo1.show;
activecontrol := makebtn;
comment.caption := 'Please set parameters.';
showmodal;
if modalresult = mrOk then begin
fname := path + 'dpgolf.dat';
readcourse;
restart1click(sender);
end;
combo1.hide;
cancelbtn.hide;
makebtn.hide;
okbutton.show;
activecontrol := okbutton;
clientheight := 118;
end;
end;
procedure TForm1.Save1Click(Sender: TObject);
var j, k, l : integer;
a, b : byte;
begin
savebox.filename := formatdatetime('mmddhhnn',now) + '.dpg';
if Savebox.execute then begin
screen.cursor := crHourGlass;
assignfile(data,savebox.filename);
rewrite(data);
for j := 1 to 18 do begin
for k := 1 to 16 do for l := 1 to 16 do begin
a := (dy[j,l,k] + 8) * 16 + (dx[j,l,k] + 8);
write(data,a);
end;
a := (hy[j] - 1) * 16 + (hx[j] - 1);
b := 255 - ((by[j] - 1) * 16 + (bx[j] - 1));
write(data,a,b);
end;
closefile(data);
screen.cursor := crDefault;
end;
end;
procedure TForm1.Load1Click(Sender: TObject);
begin
if loadbox.execute then begin
fname := loadbox.filename;
readcourse;
restart1click(sender);
end;
end;
procedure TForm1.Exit1Click(Sender: TObject);
begin
Application.terminate;
end;
procedure TForm1.Help1Click(Sender: TObject);
begin
application.helpjump('HID_N0001');
end;
procedure TForm1.About1Click(Sender: TObject);
begin
aboutbox.comment.caption := 'Welcome to Danchan Golf Club!';
aboutbox.showmodal;
end;
procedure TForm1.Shape1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var r, s : real;
begin
r := (60-x) * sqrt(abs(60-x)) * 0.1;
s := (60-y) * sqrt(abs(60-y)) * 0.1;
showxy.caption := 'Power : ' + inttostr(round(sqrt(r*r+s*s))-2);
end;
procedure TForm1.Shape1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
nopress := true;
end;
procedure TForm1.Shape1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; MX, MY: Integer);
begin
if nopress and nomove then begin
nopress := false;
label4.hide;
nomove := false;
bdx := (60-mx) * sqrt(abs(60-mx)) * 0.00295;
bdy := (60-my) * sqrt(abs(60-my)) * 0.00295;
game1.enabled := false;
timer1.enabled := true;
repeat application.processmessages
until (abs(bdx) < 0.049) and (abs(bdy) < 0.049);
timer1.enabled := false;
formpaint(sender);
hata.repaint;
game1.enabled := true;
if cupin then begin
case shot of
1 : aboutbox.comment.caption := 'Great Birdy !';
2 : aboutbox.comment.caption := 'Nice Par.';
3 : aboutbox.comment.caption := 'Boggy...';
4 : aboutbox.comment.caption := 'Double Boggy ...';
5 : aboutbox.comment.caption := 'Triple Boggy ...'
else aboutbox.comment.caption :=
'Cup in ( +' + inttostr(shot-2) + ' )';
end;
aboutbox.showmodal;
inc(score,shot);
shot := 1;
if hole = 18 then begin
pmstr(score-36);
with aboutbox do begin
comment.caption := 'Finish :' + form1.label3.caption;
showmodal;
comment.caption := 'Save this course ?';
cancelbtn.show;
showmodal;
if modalresult = mrOk then save1click(sender);
end;
new1click(sender);
if modalresult <> mrOk then restart1click(sender);
end else begin
inc(hole);
pmstr(score - (hole - 1) * 2);
showhole;
end;
end else begin
inc(shot);
label2.caption := 'Shot ' + inttostr(shot);
end;
label4.show;
nomove := true;
end;
end;
procedure TForm1.Shape2MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
showxy.caption := 'Power : 0';
end;
procedure TForm1.Bar1Change(Sender: TObject);
begin
label5.caption := 'Friction : ' + inttostr(bar1.position);
fr := 1 - bar1.position * 0.005;
end;
procedure TForm1.Bar2Change(Sender: TObject);
begin
label6.caption := 'Acceleration : ' + inttostr(bar2.position);
ac := 0.0005 + bar2.position * 0.0001;
end;
procedure TForm1.ResetbtnClick(Sender: TObject);
begin
bar1.position := 14;
bar2.position := 14;
end;
procedure TForm1.Check1Click(Sender: TObject);
begin
radio1.enabled := check1.checked;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var xx, yy : integer;
begin
bdx := bdx * fr + dx[hole,trunc(x),trunc(y)] * ac;
bdy := bdy * fr + dy[hole,trunc(x),trunc(y)] * ac;
x := x + bdx;
y := y + bdy;
if (x < 1.1) or (x >= 16.9) or (y < 1.1) or (y >= 16.9) then begin
bdx := 0;
bdy := 0;
end;
if (x < 1.1) then x := 1.1 else if (x > 16.9) then x := 16.9;
if (y < 1.1) then y := 1.1 else if (y > 16.9) then y := 16.9;
canvas.ellipse(round(x*26)-29,round(y*26)-29,round(x*26)-22,round(y*26)-22);
xx := trunc(x);
yy := trunc(y);
if map[hole,xx,yy] = 0 then begin
bdx := bdx * 0.85;
bdy := bdy * 0.85;
end;
if (xx = hx[hole]) and (yy = hy[hole]) and (bdx*bdx+bdy*bdy < 0.1) and
(trunc((x-xx)*3) = 1) and (trunc((y-yy)*3) = 1) then begin
bdx := 0.0;
bdy := 0.0;
cupin := true;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
randomize;
nopress := true;
nomove := true;
clientheight := 26 * 16;
clientwidth := 26 * 16 + panel1.width;
path := extractfilepath(application.exename);
fname := path + 'dpgolf.dat';
readcourse;
restart1click(sender);
fr := 0.93;
ac := 0.0019;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (key = VK_Shift) and check1.checked and (radio1.itemindex mod 2 = 0)
then radio1.itemindex := 2 - radio1.itemindex;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; MX, MY: Integer);
begin
if check1.checked and nopress then begin
nopress := false;
mx := mx div 26 + 1;
my := my div 26 + 1;
case radio1.itemindex of
0 : case button of
mbLeft : dx[hole,mx,my] := (dx[hole,mx,my] + 23) mod 16 - 8;
mbRight : dx[hole,mx,my] := (dx[hole,mx,my] + 9) mod 16 - 8;
end;
1 : begin
dx[hole,mx,my] := 0;
dy[hole,mx,my] := 0;
end;
2 : case button of
mbLeft : dy[hole,mx,my] := (dy[hole,mx,my] + 23) mod 16 - 8;
mbRight : dy[hole,mx,my] := (dy[hole,mx,my] + 9) mod 16 - 8;
end;
3 : case button of
mbLeft : begin
hx[hole] := mx;
hy[hole] := my;
end;
mbRight : begin
bx[hole] := mx;
by[hole] := my;
x := mx + 0.5;
y := my + 0.5;
end;
end;
end;
if (dx[hole,mx,my] = 0) and (dy[hole,mx,my] = 0)
then map[hole,mx,my] := 0 else map[hole,mx,my] := 1;
formpaint(sender);
hata.left := (hx[hole] - 1) * 26 + 8;
hata.top := (hy[hole] - 1) * 26 - 15;
hata.refresh;
end;
end;
procedure TForm1.FormPaint(Sender: TObject);
var i, j : byte;
k, l : integer;
begin
for i := 1 to 16 do for j := 1 to 16 do begin
k := map[hole,j-1,i] + map[hole,j,i-1] * 2 +
map[hole,j+1,i] * 4 + map[hole,j,i+1] * 8;
rect2 := rect((j-1)*26,(i-1)*26,j*26,i*26);
if map[hole,j,i] = 1 then begin
case k of
0..4 : rect1 := rect(k*26,0,(k+1)*26,26);
6 : rect1 := rect(130,0,156,26);
8 : rect1 := rect(156,0,182,26);
9 : rect1 := rect(182,0,208,26);
12: rect1 := rect(208,0,234,26)
else rect1 := rect(234,0,260,26);
end;
canvas.copyrect(rect2,image2.picture.bitmap.canvas,rect1);
end else begin
case k of
3 : rect1 := rect(0,0,26,26);
6 : rect1 := rect(26,0,52,26);
7 : rect1 := rect(52,0,78,26);
9 : rect1 := rect(78,0,104,26);
11..15 : rect1 := rect((k-7)*26,0,(k-6)*26,26)
else rect1 := rect(234,0,260,26);
end;
canvas.copyrect(rect2,image3.picture.bitmap.canvas,rect1);
end;
end;
canvas.pen.color := clwhite;
canvas.brush.color := clred;
for i := 1 to 16 do for j := 1 to 16 do if map[hole,j,i] = 1 then begin
k := i*26-13;
l := j*26-13;
canvas.polygon([point(l+dx[hole,j,i]*2,k+dy[hole,j,i]*2),
point(l-dx[hole,j,i]*2+dy[hole,j,i],k-dy[hole,j,i]*2-dx[hole,j,i]),
point(l-dx[hole,j,i]*2-dy[hole,j,i],k-dy[hole,j,i]*2+dx[hole,j,i])]);
end;
if not cupin then with canvas do begin
pen.color := clBlack;
brush.color := clWhite;
ellipse(round(x*26)-29,round(y*26)-29,round(x*26)-22,round(y*26)-22);
end;
end;
end.